package com.itrencai.d16_socket.socketduo2;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.util.Scanner;

//完成socket网络变成入门案例的客户端开发，实现多发多收
public class ClientDemo2 {
    public static void main(String[] args)  {
        //1.创建socket通信管道实现与服务端的链接
         //public Socket(String host, int port)
        //参数一：服务端的ip地址
        //参数二：服务端的端口
        try {
            System.out.println("==============客户端启动成功============");

            Socket socket =new Socket("127.0.0.1",7777);
            //2.从socket通信管道中得到字节数输出流，负责发送数据
            OutputStream os=socket.getOutputStream();
            //3.把低级的字节流包装成打印流
            PrintStream ps=new PrintStream(os);
            Scanner sc=new Scanner(System.in);
            while (true) {
                //4.发送消息
                System.out.println("请说：");
                String msg=sc.nextLine();
                ps.println(msg);
                ps.flush();
            }
            //关闭资源
            //socket.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}
